package com.tlgen.service;

import com.tlgen.mapper.AssistMapper;
import com.tlgen.model.Assist;
import com.tlgen.model.RespPageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

/**
 * @author: tlgen
 * @Discription:
 */
@Service
public class AssistService {

    @Autowired
    AssistMapper assistMapper;

    public List<Assist> getAllAssists() {
        return assistMapper.getAllAssists();
    }

    public Integer addAssist(Assist assist) {
        assist.setCreateDate(new Date());
        assist.setEnabled(true);
        return assistMapper.insertSelective(assist);
    }

    public Integer updateAssist(Assist assist) {
        return assistMapper.updateByPrimaryKeySelective(assist);
    }

    public Integer deleteAssistById(Integer id) {
        return assistMapper.deleteByPrimaryKey(id);
    }

    public Integer deleteAssistByIds(Integer[] ids) {
        return assistMapper.deleteAssistByIds(ids);
    }

    public RespPageBean getAssistByPageWithSalary(Integer page, Integer size) {
        if (page != null && size != null) {
            page = (page - 1) * size;
        }
        List<Assist> list = assistMapper.getAssistByPageWithSalary(page, size);
        RespPageBean respPageBean = new RespPageBean();
        respPageBean.setData(list);
        respPageBean.setTotal(assistMapper.getTotal(null));
        return respPageBean;
    }

    public Integer updateAssistSalaryById(Integer aid, Integer sid) {
        return assistMapper.updateAssistSalaryById(aid, sid);
    }
}
